<template>
  <div class="order-history"
       ref="history">
    <div class="history-header">{{$t("message.orderHistory")}}</div>
    <div class="back"
         @click="$emit('closeHistory')">
      <div class="arrow_lift arrow_lift-post"
           style="top:0;margin-left:0">
        <img src="../../../static/imgs/ret3.png"
             height="40"
             width="" />
      </div>
    </div>
    <div class="no-history"
         v-show="history.length==0">
      <span>{{$t("message.noHistory")}}</span></div>
    <div class="foods-wrapper">
      <div ref="historyFoodsWrapper">
        <ul class="food-list"
            ref="histirylist">
          <li v-for="(item ,itemindex) in history" :key="itemindex">
            <h1 class="header-title">
              <span class="order-num">{{$t("message.orderNum")}}</span>{{item.dno}}
              <span class="order-time">{{item.time}}</span></h1>
            <ul class="ul-wrapper">
              <li v-for="(food,foodindex) in item.det" :key="foodindex"
                  class="food-item border-bottom-1px">
                <div class="icon">
                  <img :src="'http://order.huaqiaobang.com' + food.img"
                       width="57"
                       height="57" />
                </div>
                <div class="content">
                  <div class="name"><span v-show="food.product_id!=0">{{food.product_id==0? '':food.product_id}}.</span>
                    {{changeFoodName(food)}}<span class="remarks">{{food.remarks=='暂无'? '':food.remarks}}</span>
                  </div>
                  <div class="options"
                       v-if="food.option_name">{{food.option_name}}</div>
                  <div class="price">
                    <p class="desc">x {{food.goodscount}}</p>
                    <span class="now">
                      {{currencyDefault}}
                      {{food.goodscost}}
                    </span>
                  </div>
                </div>
              </li>
            </ul>
            <div style="text-align: right;padding:10px;color: red;">{{currencyDefault}} {{item.allcost}}</div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import BScroll from 'better-scroll'
import bus from '../../store/bus.js'

export default {
  name: 'orderHistory',
  props: {
    // 货币单位
    currencyDefault: {
      type: String
    },
    // 历史订单
    history: {
      type: Array
    },
    tableNum: {
      type: Number
    }
  },
  data () {
    return {
      historyInd: 0,
    }
  },
  created () {
    this.change()
    // this.history()
  },
  watch: {
    // history () {
    //   this.$nextTick(() => {
        // this._initScroll()
        // this.foodsScrol()
        // this.scroll()
    //   })
    // },
    histirylist () {
 
    }

  },
  methods: {
    change () {
      bus.$on('shopcatr_type', (res, index) => {
        this.historyInd = index
      })
    },
    //  切换菜名多语言
    changeFoodName (item) {
      switch (this.historyInd) {
        case 0:
          return item.name
        case 1:
          return item.en_name
        case 2:
          return item.zh_cn_name
        case 3:
          return item.de_name
      }
    },
  },


  mounted () {
    if(false){
    this.$nextTick(() => {
      new BScroll('.food-list', {
        scrollY: true,
        click: true
      })
    })
    }

  }
}
</script>
<style lang="stylus" scoped>
.order-history {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 1px;
  width: 100%;
  background: white;
  z-index: 999;

  .history-header {
    width: 100%;
    height: 50px;
    line-height: 50px;
    text-align: center;
  }

  .no-history {
    position: fixed;
    top: 50px;
    width: 100%;
    height: 100%;
    text-align: center;

    span {
      display: inline-block;
      margin-top: 50%;
      color: rgb(147, 153, 159);
      font-size: larger;
    }
  }

  .back {
    position: absolute;
    top: 0px;
    left: 5px;
    height: 0px;

    .arrow_lift {
      width: 10px;
      height: 10px;
      padding: 10px;
      font-size: 20px;
      color: #fff;
    }
  }

  .foods-wrapper {
    width: 100%;
    height: 100%;
    background: #fff;
    overflow: auto;

    .food-list {
      padding-bottom: 50px;

      .header-title {
        padding-left: 14px;
        height: 26px;
        line-height: 26px;
        border-left: 2px solid #d9dde1;
        font-size: 12px;
        color: #93999f;
        background: #f3f5f7;

        .order-num, .order-time {
          margin-right: 5px;
        }

        .order-time {
          float: right;
        }
      }

      .food-item {
        display: flex;
        justify-content: space-between;
        border-bottom: 1px solid rgba(7, 17, 27, 0.1);
        padding: 10px;

        .icon {
          flex: 0 0 60px;
        }

        .content {
          flex: 1;
          padding-left: 10px;

          .name {
            margin: 0 0 8px 0;
            font-size: 13px;
            color: rgb(7, 17, 27);

            .remarks {
              color: red;
              font-size: 10px;
              margin-left: 2px;
            }
          }

          .options {
            font-size: 14px;
            color: #93999f;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }

          .price {
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-weight: 700;
            line-height: 24px;

            .now {
              font-size: 14px;
              color: rgb(240, 20, 20);
            }

            .desc {
              color: rgb(147, 153, 159);

              .back .arrow_lift {
                position: static !important;
              }
            }
          }
        }
      }
    }
  }
}
</style>
